﻿define('ui/controller/conditionController', 
	['local/constants',], function(constants) {

	var conditionController = {
			
		initial: function(){
			conditionController.hideOuterBox();
			conditionController.hideConditionList();
		},
		
		changeShowStatus: function(itemKey){
			for(var i=0; i<constants.conditionData.list.length; i++) {
				var d = constants.conditionData.list[i];
				if(d["itemFlag"].indexOf(itemKey)!=-1 || d["itemFlag"].indexOf("all")!=-1) {
					d["ShowStatus"] = true;
				}else {
					d["ShowStatus"] = false;
				}
				
			}
		},
		
		render: function() {
			AMapUI.loadUI(['misc/MarkerList'], function(MarkerList) {
				var typeList = '<% for(var i=0;i < data.length;i++) { %>'+  
									'<% if(data[i].ShowStatus) { %>'+
									'<em class="<%- data[i].class %>" data-val="query_type=<%- data[i].queryType %>" data-spm-anchor-id="" style="border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(224, 224, 224);">'+
										'<span data-spm-anchor-id="">'+
											'<%- data[i].bussinessName %>'+
										'</span>'+
										'<span class="caret">'+
										'</span>'+
									'</em>'+
									'<% } %>'+
								 '<% } %>';
				var html = MarkerList.utils.template(typeList, {data: constants.conditionData.list});  
				$("#content").html("").html(html); 
				conditionController.onSelect();
			});
		},
			
		onSelect: function (item) {
			$("p>em").each(function(){
				$(this).click(function(){
					var val = $(this).attr('data-val');
					conditionController.triggerToggle(val.split("=")[1]);
				});
			});
		},
		
		triggerToggle: function(id) {
			$(".classsify-down").not("#"+id).css({"display":"none"});
			$("#"+id).slideToggle(200);
		},
		
		hideOuterBox: function(){
			$(".classify").css({"display":"none"});
		},
		
		showOuterBox: function(){
			$(".classify").css({"display":"block"});
		},
		
		showConditionList: function(){
			$(".classsify-down").css({"display":"none"});
		},
		
		hideConditionList: function(){
			$(".classsify-down").css({"display":"none"});
		},
		
		/**
		 * 设置条件栏地区的选中编码值
		 */
		setAreaCode:function($span, code){
			$span.attr('data-spm-anchor-id', code);
		},
		/**
		 * 获取条件栏地区的选中编码值
		 */
		getAreaCode:function(){
			var $span = $("em.cl-area>span").first();
			return $span.attr('data-spm-anchor-id');
		},
		
		/**
		 * 设置条件栏行业的选中编码值
		 */
		setTradeCode:function($span, code){
			$span.attr('data-spm-anchor-id', code);
		},
		
		/**
		 * 获取条件栏行业的选中编码值
		 */
		getTradeCode:function(){
			var $span =$("em.cl-trade>span").first();
			return $span.attr('data-spm-anchor-id');
		},
		/**
		 * 设置条件栏监管类型的选中编码值
		 */
		setControlLevelCode:function($span, code){
			$span.attr('data-spm-anchor-id', code);
		},
		/**
		 * 获取条件栏监管类型的选中编码值
		 */
		getControlLevelCode:function(){
			var $span =$("em.cl-type>span").first();
			return $span.attr('data-spm-anchor-id');
		},
		
		/**
		 * 获取高级筛选表单参数
		 */
		getFormParamsData: function() {
			var param = {};
			
			var s = $('#advForm').serialize();
			var sa = s.split("&");
			if(sa && sa.length>0){
				$.each(sa, function(i, e){
					var kv = e.split('=');
					if(kv && kv.length>0){
						param[kv[0]] = kv[1];
					}
				});
			}
			param.processTechIds="";
			$("input[name='processTechCheckbox']:checked").each(function(){
				param.processTechIds += "," + $(this).val();
			});
			if(param.processTechIds.length>0) {
				param.processTechIds = param.processTechIds.substring(1);
			}
			
			return param;
		},
		/**
		 * 获取排口类型编码
		 */
		getPointTypeCode: function() {
			return '';
		},
		/**
		 * 设置条件栏年份的选中值
		 */
		setYearCode:function($span, code){
			$span.attr('data-spm-anchor-id', code);
		},
		/**
		 * 获取条件栏年份的选中值
		 */
		getYearCode:function(){
			var $span =$("em.cl-year>span").first();
			return $span.attr('data-spm-anchor-id');
		},
		
		/**
		 * 获取条件栏排污许可量或者实际排放量的选中值
		 */
		getPermitActualPolluteCode:function(){
			return $("#permitAcutalPolluteCode").val();
		},
		
	};
	
	return conditionController;
});